<template>
	<view class="houseAcceptance">
		<view class="content">
			<text selectable="true">复制链接： {{ drawing || '暂无链接' }}</text>
		</view>
		<view class="content" v-for="(item, i) in houseInfo" :key="i">
			<view class="title">
				<text>房源地址: {{ item.houseAddress }}</text>
			</view>
			<view class="content-list">
				<text>业主名称: {{ item.houseName || '无' }}</text>
				<text>房型: {{ item.roomType }}</text>
			</view>
			<view class="content-list">
				<text>监理姓名: {{ item.supervisionName || '保密' }}</text>
				<text>工长姓名: {{ item.foremanName || '保密' }}</text>
			</view>
			<view class="content-list">
				<text>瓦工姓名: {{ item.bricklayerName || '保密' }}</text>
				<text>木工姓名: {{ item.carpenterName || '保密' }}</text>
			</view>
			<view class="content-list">
				<text>水电工姓名: {{ item.plumberName || '保密' }}</text>
				<text>油漆工姓名: {{ item.painterName || '保密' }}</text>
			</view>
			<view class="content-list">
				<text>开工时间: {{ item.startTime }}</text>
				<text>竣工时间: {{ item.endTime || '未竣工' }}</text>
			</view>
			<view class="house-buttom">
				<button class="mini-btn" type="default" size="mini" @click="downloadDrawing(item)">下载图纸</button>
				<button class="mini-btn" type="default" size="mini" @click="lookAcceptance(item)">查看验收</button>
			</view>
		</view>
		<view class="more" v-if="houseInfo.length === 0">没有信息</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			drawing: '',
			houseInfo: []
		}
	},
	onLoad() {
		let params = {
			houseOwnerId: uni.getStorageSync('userInfo').id,
			page: 1,
			limit: 99999
		}
		this.init(params)
	},
	methods: {
		init(params) {
			this.$api
				.getHouseInfos(params)
				.then(res => {
					if (res.success) {
						this.houseInfo = res.rows
					} else {
						uni.showToast({ title: res.msg })
					}
				})
				.catch(err => {
					console.log('request fail', err)
				})
		},
		downloadDrawing(item) {
			// window.open(item.drawing)
			this.drawing = item.drawing
			uni.showModal({
				title: '提示',
				content: '请在上方复制链接到浏览器',
				success: function(res) {
					if (res.confirm) {
						console.log('用户点击确定')
					} else if (res.cancel) {
						console.log('用户点击取消')
					}
				}
			})
		},
		lookAcceptance(item) {
			uni.navigateTo({
				url:
					'../lookAcceptance/lookAcceptance?id=' +
					item.id +
					'&bricklayerId=' +
					item.bricklayerId +
					'&carpenterId=' +
					item.carpenterId +
					'&plumberId=' +
					item.plumberId +
					'&painterId=' +
					item.painterId
			})
		}
	}
}
</script>

<style lang="scss">
.houseAcceptance {
	.content {
		view {
			line-height: 50rpx;
		}
		margin: 20rpx;
		padding: 20rpx;
		box-shadow: 0 0 16rpx #999;
		border-radius: 10rpx;
		.title {
			font-weight: bold;
		}
		.content-list {
			display: flex;
			text {
				width: 50%;
			}
		}
	}
	.more {
		text-align: center;
		padding: 20rpx;
		font-size: 32rpx;
	}
	.house-buttom {
		display: flex;
		justify-content: center;
	}
}
</style>
